#include "./app_task.h"
#include "../driver/cmd_uart.h"
#include "../device/compat.h"
#include "../service/conn.h"
#include "./handler_task.h"
#include "../driver/sensor.h"
#include "../driver/elock.h"
#include "../driver/ctrl.h"
#include "./status_task.h"
#include "../driver/analog.h"

namespace task {

AppTask appTask;

using namespace driver;
using namespace service;

static void afio_init() {
    RCU_APB2EN |= RCU_APB2EN_AFEN;
    
    uint32_t tmp = AFIO_PCF0 & (~AFIO_PCF0_SWJ_CFG) | (0x02 << 24);
    AFIO_PCF0 = tmp;
}

void AppTask::run() {

    afio_init();
    cmdUart.init();
    sensor.init();
    elock.init();
    ctrl.init();
    analog.init();

    statusTask.start();
    handlerTask.init_start();

    service::conn_loop();   
}


}
